<?php

/**
 * transfer the mutation
 * to DP Out table
 *
 */
$CLFetchers->fetchLstDataDetail($Db,
                                $jobId,
                                $SourceDb->fetchValue("srcDbDtl"),
                                $nDetail,
                                $lstDetail);

if($isApprove){

  $amount = $lstDetail["TOT_NET"][0];

  $values = "  ".$periode.",    ".
            " '".$lstHeader["SUPPLIER_CUSTOMER"][0]."', ".
            " '".$refId."',      ".
            " ' ',   ".
            "  ".$hdrDate.",  ".
            "  ".$hdrDate.",   ".
            "  ".$hdrDate.",  ".
            "  ".$txType.",   ".
            "  ".$amount." ,  ".
            "  1              "; /* Last Mutation Number, default is 1 */

  $CLHandlers->insToMutDp($Db,
                          "SUPPLIER_CODE",
                          $values,
                          $SourceDb->fetchValue("srcDbMutDpSupplier"));
}else{

  /**
   * check if transaction is clean
   */
  $CLFetchers->fetchLastMutationNo($Db,
                                   $refId,
                                   $SourceDb->fetchValue("srcDbMutDpSupplier"),
                                   $subDtlNo);

  /**
   * if we have more than 1 entry
   */
  if($subDtlNo > 1){

    $Misc->usrDieJs("Error: Tx is not clean");
  }else{

    /*Do nothing*/
  }

  /**
   * since this is the first tx
   * of mut_dp_supplier/customer
   * then source and reference are the same
   */
  $CLHandlers->delEntDp($Db,
                        $refId,
                        $refId,
                        $SourceDb->fetchValue("srcDbMutDpSupplier"));
}

if($isApprove){

  /**
   * write to header of cash bank source
   * the MUT_CASH_BANK_DETAIL
   */
  $CLFetchers->fetchLastMutCbDtlNo($Db,
                                   $_SESSION["sysPeriode"],
                                   $SourceDb->fetchValue("srcDbMutCbDtl"),
                                   $mutCbDtlNo);

  $values = " '".$refId."',                     ".
            " '".$lstHeader["C_B_CODE"][0]."',  ".
            "  ".$mutCbDtlNo.",   ".
            "  ".$periode.",    ".
            "  ".$hdrDate.",    ".
            " '".$lstHeader["SUPPLIER_CUSTOMER"][0]."', ".
            "  ".$txType.",                     ".
            " '".$lstHeader["CURRENCY"][0]."',  ".
            "  ".$lstHeader["RATE"][0].",       ".
            "  ".$lstDetail["TOT_AMOUNT"][0].", ".
            "  ".$lstDetail["TOT_NET"][0]."     ";

  $CLHandlers->insToMutCbDtl($Db,
                             $values,
                             $SourceDb->fetchValue("srcDbMutCbDtl"));
}else{

  $CHandlers->dbEntDelete($Db,
                          $jobId,
                          $SourceDb->fetchValue("srcDbMutCbDtl"));
}

?>